package com.cloud.basic.webservice;

import com.cloud.basic.Utils.DateUtils;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.JaxWsClientFactoryBean;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.xml.ws.soap.SOAPBinding;
import java.util.Date;

/**
 * @program: basic
 * @description: 客户端
 * @author: Cloud
 * @create: 2021/10/19 11:37:26
 */
public class WebServiceClient {


    public static void getView03() {
        JaxWsDynamicClientFactory proxyFactoryBean =  JaxWsDynamicClientFactory.newInstance();
        JaxWsClientFactoryBean jaxWsClientFactoryBean = new JaxWsClientFactoryBean();
        jaxWsClientFactoryBean.setBindingId(SOAPBinding.SOAP11HTTP_BINDING);
        Client client = proxyFactoryBean.createClient("http://183.238.29.26:22360/wsdl/IhzbAttenService");
        Object[] objects = new Object[0];
        try {
            // 添加卡号
            objects = client.invoke("lockStitch_LockTestor", "ALI_TEST01", "8657710552917850", "C554D90E8B5110F3", "36", "03", "568872", "2021-11-24 08:47:00", "2031-11-19 15:59:58");
            System.out.println("返回数据:" + objects[0]);
//            objects = client.invoke("lockStitch_GetResult", "ALI_TEST01", "88339", "8657710552917850","36");
//            System.out.println("返回数据:" + objects[0]);
        } catch (java.lang.Exception e) {
            e.printStackTrace();
        }
    }

    public static void getView02() {
        JaxWsDynamicClientFactory proxyFactoryBean =  JaxWsDynamicClientFactory.newInstance();
        Client client = proxyFactoryBean.createClient("http://www.webxml.com.cn/WebServices/WeatherWebService.asmx");
        // 需要密码的情况需要加上用户名和密码
        // client.getOutInterceptors().add(new ClientLoginInterceptor(USER_NAME,PASS_WORD));
        Object[] objects = new Object[0];
        try {
            // invoke("方法名",参数1,参数2,参数3....);
            objects = client.invoke("getWeatherbyCityName","南宁");
            System.out.println("返回数据:" + objects);
        } catch (java.lang.Exception e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("/receive")
    @ResponseBody
    public static void getView(){
        JaxWsDynamicClientFactory proxyFactoryBean =  JaxWsDynamicClientFactory.newInstance();
        Client client = proxyFactoryBean.createClient("http://localhost:8081/wbs/user-server?wsdl");
        // 需要密码的情况需要加上用户名和密码
        // client.getOutInterceptors().add(new ClientLoginInterceptor(USER_NAME,PASS_WORD));
        Object[] objects = new Object[0];
        try {
            // invoke("方法名",参数1,参数2,参数3....);
            objects = client.invoke("sayHello", "1002","李四");
            System.out.println("返回数据:" + objects[0]);
        } catch (java.lang.Exception e) {
            e.printStackTrace();
        }
    }

    //返回数据:{"8657710552917850":
    // {"PowerPlug":[{"macid":"B3FB589822654E26","name":"计量插座24G(E26)","power":"2"},
    // {"macid":"641CA717E4991C6F","name":"计量插座24G(C6F)","power":"55449"}],
    // "DoorMagn":[{"macid":"F32170DC94EF30C9","name":"门磁报警器(0C9)","state":"开"}]}}
    public static void getView01() {
        JaxWsDynamicClientFactory proxyFactoryBean =  JaxWsDynamicClientFactory.newInstance();
        JaxWsClientFactoryBean jaxWsClientFactoryBean = new JaxWsClientFactoryBean();
        jaxWsClientFactoryBean.setBindingId(SOAPBinding.SOAP11HTTP_BINDING);
        Client client = proxyFactoryBean.createClient("http://183.238.29.26:22360/wsdl/IhzbAttenService");
//        Client client = proxyFactoryBean.createClient("http://183.238.29.26:22360/wsdl/IhzbAttenService");
        Object[] objects = new Object[0];
        try {
            // 一个星期
            Date date1 = DateUtils.addDateDays(new Date(), 7);
//            DateUtils.format(new Date(),DateUtils.DATE_TIME)
//            objects = client.invoke("lockStitch_LockTestor", "ALI_TEST01", "8657710552917850", "6F73E7D8D78652B8", "24", "21", "6F73E7D8D78652B8030000", "2021-11-19 13:47:00", "2021-11-19 15:59:58");
            objects = client.invoke("lockStitch_LockTestor", "ALI_TEST01", "8657710552917850", "C554D90E8B5110F3",
                                                    "36", "3", "123456", "2022-01-11 11:11:11", DateUtils.format(date1,DateUtils.DATE_TIME));
//            Object[] getResult = client.invoke("lockStitch_GetResult","ALI_TEST01","5","8644240431728960","24");
//            Object[] getIotLists = client.invoke("lockStitch_GetIotList","ALI_TEST01","ALI_TEST01","0801075500100323");
//            Object[] getIotStatuses = client.invoke("lockStitch_GetIotStatus","ALI_TEST01","8657710552917850");
            System.out.println("返回数据:" + objects[0]);
//            System.out.println("返回数据:" + getResult[0]);
//            System.out.println("返回数据:" + getIotStatuses[0]);
//            System.out.println("返回数据:" + getIotStatuses[0]);
        } catch (java.lang.Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        getView02();
    }

}
